package JVM;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;



public class test_123123 {
    static ReentrantLock lock=new ReentrantLock();
    static Condition codition_1=lock.newCondition();
    static Condition codition_2=lock.newCondition();
    static  int i=1;
    static class myThread1 extends Thread{
        @Override
        public void run() {
            try {
                while (true) {
                    lock.lock();
                    while (i != 1)
                        codition_1.await();
                    System.out.println("t1");
                    i=2;
                    codition_2.signal();
                    lock.unlock();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();

            }
        }
    }
    static class myThread2 extends Thread{
        @Override
        public void run() {
            try {
                while (true) {
                    lock.lock();
                    while (i != 2)
                        codition_2.await();
                    System.out.println("t2");
                    i=1;
                    codition_1.signal();
                    lock.unlock();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
            }
        }
    }

    public static void main(String[] args) {
        new myThread1().start();
        new myThread2().start();
    }

//
//2、2、输入2个数字字符串，每个字符串超过200字符，请输出相加后的结果。
    // TODO
    public static String add(String s1,String s2){
        StringBuffer sb=new StringBuffer();
        char[] num1 = s1.toCharArray();
        char[] num2 = s2.toCharArray();
        int extra=0;
        int i=num1.length-1,j=num2.length-1;
        for (;i>=0&&j>=0;i--,j--){
            int n1=num1[i]-'0';
            int n2=num2[j]-'0';
            int res=n1+n2+extra;
            if (res<9){
                sb.append(res);
            }else{
                extra=res-9;
                sb.append(res-10);
            }
        }
        while (i!=0){
            int res=num1[i]-'0'+extra;
            if (res<9){
                sb.append(res);
            }else{
                extra=res-9;
                sb.append(res-10);
            }
        }
        while (j!=0){
            int res=num1[j]-'0'+extra;
            if (res<9){
                sb.append(res);
            }else{
                extra=res-9;
                sb.append(res-10);
            }
        }
        return sb.reverse().toString();
    }
}
